angular.module('mamApp').controller('albumAdjustModalController', ['$scope', 'AlbumManager', '$uibModalInstance', 'param', 'ChannelManager','CommonManager',
    function ($scope, AlbumManager, $uibModalInstance, param, ChannelManager,CommonManager) {
        $scope.search = {categoryId: "", channelId: ""};
        $scope.categories = param.categories;

        //一级频道初始
        CommonManager.categoriesList().then(function (result) {
            $scope.categories = [{categoryId: "", categoryName: "一级频道"}].concat(result.data.pageList);

        })
        //二级频道初始
        $scope.channels = [{channelId: "", channelName: "二级频道"}];

        //一级频道选择-->二级频道变化
        $scope.categoryChange = function (channelId) {
            $scope.search.channelId = "";
            $scope.channels = [{channelId: "", channelName: "二级频道"}];
            CommonManager.channelList($scope.search.categoryId).then(function (result) {
                if (channelId){
                    $scope.channels = $scope.channels.concat(result.data.pageList)
                }
            })
        };

        $scope.modelOk = function () {
            AlbumManager.albumAdjustChannel(param.ids,$scope.search).then(function (result) {
                if(result.data.c=="s"){
                    $uibModalInstance.close("ok");

                }else{
                    $uibModalInstance.close("error");

                }
            })
        };

        $scope.modelCancel = function () {
            $uibModalInstance.close("cancel");
        };
        
        
        
    }])

